package com.zxl.security.core.social.weixin.connect;

import com.zxl.security.core.social.weixin.api.WeiXin;
import com.zxl.security.core.social.weixin.api.WeiXinUserInfo;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;

@NoArgsConstructor
@AllArgsConstructor
public class WeiXinAdapter implements ApiAdapter<WeiXin> {
    private String openId;

    @Override
    public boolean test(WeiXin api) {
        // 用于测试微信api是否可用，这里不做过多去测试，直接返回true
        return true;
    }

    @Override
    public void setConnectionValues(WeiXin api, ConnectionValues values) {
        // 这里做微信返回数据进行适配
        WeiXinUserInfo userInfo = api.getUserInfo(openId);
        values.setProviderUserId(userInfo.getOpenid());
        values.setDisplayName(userInfo.getNickname());
        values.setImageUrl(userInfo.getHeadimgurl());
        values.setProfileUrl(null);
    }

    @Override
    public UserProfile fetchUserProfile(WeiXin api) {
        return null;
    }

    @Override
    public void updateStatus(WeiXin api, String message) {

    }
}
